package com.maodou.android.data.remote

import com.maodou.core.network.HttpConfig
import com.maodou.core.network.NetworkFactory
import retrofit2.create

/**
 * 提供一个构建 ApiService 的工厂（配置 BaseUrl、Header、OkHttp、Retrofit）
 */
object NetworkServiceFactory {

    /**
     * 新增重载：允许注入 401/403 处理回调
     */
    fun create(
        baseUrl: String,
        isDebug: Boolean,
        headerProvider: DynamicHeaderProvider,
        unauthorizedHandler: ((code: Int) -> Unit)?
    ): ApiService {
        val config = HttpConfig(
            baseUrl = baseUrl,
            isDebug = isDebug,
            headerProvider = { headerProvider.getHeaders() },
            unauthorizedHandler = unauthorizedHandler
        )
        val retrofit = NetworkFactory.createRetrofit(config)
        return retrofit.create()
    }
}